<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <h1>微博详情页面</h1>
  <h2>
    {{weibo.nickname}}说:{{weibo.content}}
  </h2>
  <img :src=weibo.url width="200px" alt="图片"><br>
  <span>{{weibo.created}}</span>
  <hr>
  <h1>评论相关</h1>
  <p>评论:</p>
  <div v-for="comment in arr">
    <a :href="'/comment.html?id='+comment.id">{{comment.username}}评论：{{comment.content}}</a>
  </div>
  <hr>
  <input placeholder="评论内容" v-model="comment.content">
  <input type="button" value="发表评论" @click="send()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            weibo: {},
          comment:{
              content:"",
            weiboId:""
          },
arr:[]
        },
        methods:{
          send(){
            axios.post("/comment/insert",v.comment).then(function (r) {
              if(r.data==1){
              alert("评论完成");
              location.reload();}else {
                alert("请登录在评论")
                location.href="/login.html";
              }
            })
          }
        },
      created:function () {
        axios.get("/weibo/selectById"+location.search).then(function (r) {
          v.weibo=r.data;
          v.comment.weiboId=v.weibo.id;
        }),

                axios.get("/comment/select"+location.search).then(function (r) {
                  v.arr=r.data;
                })
      }
    })
</script>
</body>
</html>